<template>
  <div id="echartPie" :style="{float:'left',width: '100%', height: '280px'}"></div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  props: {
    data: Array,
  },
  mounted() {
    // this.init()
  },
  watch: {
    data(n, o) {
      this.init()
    },
  },
  methods: {
    init() {
      // 基于准备好的dom，初始化echarts实例
      const myChart = echarts.init(document.getElementById('echartPie'))
      // 绘制图表
      myChart.setOption({
        title: {
          text: '文章分布',
          subtext: '',
          left: 'center',
        },
        tooltip: {
          trigger: 'item',
        },
        legend: {
          orient: 'vertical',
          left: 'left',
        },
        series: [
          {
            name: '标签',
            type: 'pie',
            radius: '50%',
            data: this.data,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)',
              },
            },
          },
        ],
      })

      //随着屏幕大小调节图表
      window.addEventListener('resize', () => {
        myChart.resize()
      })
    },
  },
}
</script>
